using System;
using System.Windows.Forms;
using System.Configuration;
using DevExpress.ExpressApp;
using FeatureCenter.Module.Win;
using DevExpress.ExpressApp.Security;
using FeatureCenter.Module.Win.Templates;
using DevExpress.ExpressApp.Xpo;

namespace FeatureCenter.Win
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
		[STAThread]
        static void Main()
        {
            //XafTypesInfo.Instance.RegisterEntity("PropertyLogicImplementation", typeof(FeatureCenter.Module.DC.IPropertyLogicImplementation));
			Application.EnableVisualStyles();
			Application.SetCompatibleTextRenderingDefault(false);
			EditModelPermission.AlwaysGranted = System.Diagnostics.Debugger.IsAttached;
			FeatureCenterWindowsFormsApplication xafApplication = new FeatureCenterWindowsFormsApplication();
            xafApplication.SplashScreen = new DevExpress.ExpressApp.Win.Utils.DXSplashScreen();
            xafApplication.CreateCustomTemplate += new EventHandler<CreateCustomTemplateEventArgs>(xafApplication_CreateCustomTemplate);

			if(ConfigurationManager.ConnectionStrings["ConnectionString"] != null) {
				xafApplication.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
			}
            DevExpress.ExpressApp.ScriptRecorder.ScriptRecorderControllerBase.ScriptRecorderEnabled = true;
            try
            {
				xafApplication.Setup();
				xafApplication.Start();
            }
            catch (Exception e)
            {
				xafApplication.HandleException(e);
            }
        }

        static void xafApplication_CreateCustomTemplate(object sender, CreateCustomTemplateEventArgs e) {
            if(e.Context.Name == TemplateContext.ApplicationWindow) {
                e.Template = new MainForm();
            }
            else if(e.Context.Name == TemplateContext.View) {
                e.Template = new DetailViewForm();
            }
        }
    }
}
